package com.lagou.controller;

import com.alibaba.fastjson.JSONObject;
import com.lagou.service.DeepSeekService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/deepSeek")
public class DeepSeekController {

    private final DeepSeekService deepSeekService;

    @Autowired
    DeepSeekController(DeepSeekService deepSeekService) {
        this.deepSeekService = deepSeekService;
    }

    @GetMapping
    @RequestMapping("/chat")
    public String chat(String question) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("text", question);
            System.out.println(jsonObject.toJSONString());
            return deepSeekService.chat(jsonObject.toString());
        } catch (IOException e) {
            return "服务器繁忙，请稍后重试！";
        }
    }
}
